<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">

        <ui:define name="content">




            <h:form >
                <p:panel toggleable="true" id="allAssigned" header="All assigned!" rendered="#{batchEntityController.selected.unassignedKg==0}">
                   
                </p:panel>
                <p:panel toggleable="true" id="batchCreate" header="Assign locations for batch ##{batchEntityController.selected.id}" rendered="#{batchEntityController.selected.unassignedKg>0}">
                    <h:panelGrid columns="3">

                        <h:outputLabel value="Amount of unassigned #{batchEntityController.selected.product.productName} : #{batchEntityController.selected.unassignedKg} Kg" for="Raw Materials Location Selection" />


                    </h:panelGrid>
                </p:panel>
                <br/>

                <p:dataGrid var="item" value="#{rawMaterialsLocationEntityController.items}" columns="5">  

                    <p:column>  
                        <p:panel header="#{item.areaCode}" style="text-align:center">  


                            <p:poll interval="1" update="pbAjax" widgetVar="poll" />  
                            <h:outputLabel value="Usage: #{item.usageKg}/#{item.capacityKg}"/>
                            <p:progressBar id="pbAjax" widgetVar="pbAjax" ajax="true" value="#{item.showBarKg}"/>

                            <br />

                            <h:outputLabel for="Remaining" value="Remaining: #{item.remainingKg}" /> 


                            <p:spinner rendered="#{batchEntityController.selected.quantity lt item.remainingKg and item.remainingKg>0}" id="minmax" style="width: 40%"
                                       value="#{item.toAddKg}" min="0" max="#{batchEntityController.selected.unassignedKg}">

                            </p:spinner>



                            <p:spinner rendered="#{batchEntityController.selected.quantity ge item.remainingKg and item.remainingKg>0}" id="minmax2" style="width: 40%" 
                                       value="#{item.toAddKg}" min="0" max="#{item.remainingKg}"/>

                            <h:commandButton disabled="#{batchEntityController.selected.unassignedKg==0 or item.remainingKg==0}" value="Assign" action="#{batchEntityController.addLocationRM}">
                                <f:setPropertyActionListener target="#{batchEntityController.rMLocation}" value="#{item}" />
                            </h:commandButton>

                        </p:panel>  
                    </p:column>  

                </p:dataGrid>  
</h:form>




        </ui:define>
    </ui:composition>

</html>
